/*
* $Id: FamilyViewSettings.cpp 152 2010-09-23 18:28:55Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "FamilyViewSettings.h"
#include "../SettingControlIds.h"
#include "Settings/DinIntDefined.h"
#include "Database/Tables/UserFieldsTable.h"
#include "Event/EventId.h"

#define FAMILY_VIEW_REG_NAME	_T("Software\\Apiary\\FamilyViewSettings")

CFamilyViewSettings::CFamilyViewSettings()
: CSettingsWithUserColumn(FAMILY_VIEW_ID, FAMILY_VIEW_REG_NAME, FALSE){
	Init();
}
CFamilyViewSettings::~CFamilyViewSettings(){}

std::map<std::tstring, std::tstring> CFamilyViewSettings::GetStates(){
	std::map<std::tstring, std::tstring> aStates = __super::GetStates();
	aStates.insert(aStates.end(), std::make_pair(STATIC_HEADER1_ID, ILanguageManager::GetLanguageManager()->GetString(SETTINGS_ID)));
	aStates.insert(aStates.end(), std::make_pair(STATIC_VIEW_ID, ILanguageManager::GetLanguageManager()->GetString(VIEW_COLUMN_ID)));
	aStates.insert(aStates.end(), std::make_pair(CHECK_BEES_ID, CCommonFunction::GetRegValue(FAMILY_VIEW_REG_NAME, CHECK_BEES_ID)));
	aStates.insert(aStates.end(), std::make_pair(CHECK_BROOD_ID, CCommonFunction::GetRegValue(FAMILY_VIEW_REG_NAME, CHECK_BROOD_ID)));
	aStates.insert(aStates.end(), std::make_pair(CHECK_HONEY_ID, CCommonFunction::GetRegValue(FAMILY_VIEW_REG_NAME, CHECK_HONEY_ID)));
	aStates.insert(aStates.end(), std::make_pair(CHECK_FRAME_ID, CCommonFunction::GetRegValue(FAMILY_VIEW_REG_NAME, CHECK_FRAME_ID)));
	aStates.insert(aStates.end(), std::make_pair(CHECK_HOUSING_ID, CCommonFunction::GetRegValue(FAMILY_VIEW_REG_NAME, CHECK_HOUSING_ID)));
	aStates.insert(aStates.end(), std::make_pair(CHECK_BIRTHDAY_BEE_QUEEN_ID, CCommonFunction::GetRegValue(FAMILY_VIEW_REG_NAME, CHECK_BIRTHDAY_BEE_QUEEN_ID)));
	aStates.insert(aStates.end(), std::make_pair(CHECK_EXIST_BEE_QUEEN_ID, CCommonFunction::GetRegValue(FAMILY_VIEW_REG_NAME, CHECK_EXIST_BEE_QUEEN_ID)));
	aStates.insert(aStates.end(), std::make_pair(CHECK_WOX_ID, CCommonFunction::GetRegValue(FAMILY_VIEW_REG_NAME, CHECK_WOX_ID)));
	aStates.insert(aStates.end(), std::make_pair(CHECK_TYPE_ID, CCommonFunction::GetRegValue(FAMILY_VIEW_REG_NAME, CHECK_TYPE_ID)));
	aStates.insert(aStates.end(), std::make_pair(CHECK_NOTE_ID, CCommonFunction::GetRegValue(FAMILY_VIEW_REG_NAME, CHECK_NOTE_ID)));
	return aStates;
}
std::map<std::tstring, std::tstring> CFamilyViewSettings::GetDefaultStates(){
	std::map<std::tstring, std::tstring> aDefault;
	aDefault.insert(aDefault.end(), std::make_pair(CHECK_TYPE_ID, CHECK_BOX_STATE_1));
	aDefault.insert(aDefault.end(), std::make_pair(CHECK_NOTE_ID, CHECK_BOX_STATE_1));
	aDefault.insert(aDefault.end(), std::make_pair(CHECK_BEES_ID, CHECK_BOX_STATE_1));
	aDefault.insert(aDefault.end(), std::make_pair(CHECK_BROOD_ID, CHECK_BOX_STATE_1));
	aDefault.insert(aDefault.end(), std::make_pair(CHECK_HONEY_ID, CHECK_BOX_STATE_1));
	aDefault.insert(aDefault.end(), std::make_pair(CHECK_FRAME_ID, CHECK_BOX_STATE_1));
	aDefault.insert(aDefault.end(), std::make_pair(CHECK_HOUSING_ID, CHECK_BOX_STATE_1));
	aDefault.insert(aDefault.end(), std::make_pair(CHECK_BIRTHDAY_BEE_QUEEN_ID, CHECK_BOX_STATE_1));
	aDefault.insert(aDefault.end(), std::make_pair(CHECK_EXIST_BEE_QUEEN_ID, CHECK_BOX_STATE_2));
	aDefault.insert(aDefault.end(), std::make_pair(CHECK_WOX_ID, CHECK_BOX_STATE_2));
	return aDefault;
}

std::map<std::tstring, std::vector<Parameter> > CFamilyViewSettings::GetParameters(){
	std::map<std::tstring, std::vector<Parameter> > aMapParameters = __super::GetParameters();
	std::vector<Parameter> aParameters;

	//static_header1     
	aParameters.push_back(Parameter(TYPE, HEADER));
	aMapParameters.insert(aMapParameters.end(), std::make_pair(STATIC_HEADER1_ID, aParameters));

	//static_view
	aParameters.clear();
	aMapParameters.insert(aMapParameters.end(), std::make_pair(STATIC_VIEW_ID, aParameters));

	//check_boxes
	aMapParameters.insert(aMapParameters.end(), std::make_pair(CHECK_HONEY_ID, aParameters));
	aMapParameters.insert(aMapParameters.end(), std::make_pair(CHECK_HOUSING_ID, aParameters));
	aMapParameters.insert(aMapParameters.end(), std::make_pair(CHECK_BIRTHDAY_BEE_QUEEN_ID, aParameters));
	aMapParameters.insert(aMapParameters.end(), std::make_pair(CHECK_EXIST_BEE_QUEEN_ID, aParameters));
	aMapParameters.insert(aMapParameters.end(), std::make_pair(CHECK_TYPE_ID, aParameters));
	aMapParameters.insert(aMapParameters.end(), std::make_pair(CHECK_NOTE_ID, aParameters));

	aParameters.push_back(Parameter(DEPENDENTS, CHECK_BEES_ID));
	aParameters.push_back(Parameter(DEPENDENTS, CHECK_BROOD_ID));
	aParameters.push_back(Parameter(DEPENDENTS, CHECK_WOX_ID));
	aMapParameters.insert(aMapParameters.end(), std::make_pair(CHECK_FRAME_ID, aParameters));
	//check_bees
	aParameters.clear();
	aParameters.push_back(Parameter(DEPENDENTS, CHECK_FRAME_ID));
	aMapParameters.insert(aMapParameters.end(), std::make_pair(CHECK_BEES_ID, aParameters));

	//check_brood
	aParameters.clear();
	aParameters.push_back(Parameter(DEPENDENTS, CHECK_FRAME_ID));
	aMapParameters.insert(aMapParameters.end(), std::make_pair(CHECK_BROOD_ID, aParameters));

	//check_wox
	aParameters.clear();
	aParameters.push_back(Parameter(DEPENDENTS, CHECK_FRAME_ID));
	aMapParameters.insert(aMapParameters.end(), std::make_pair(CHECK_WOX_ID, aParameters));

	return aMapParameters;
}

std::vector<Window> CFamilyViewSettings::GetWindows(){
	std::vector<Window> aWindows = __super::GetWindows();
	aWindows.push_back(Window(STATIC, 10, 0, 415, 23, SS_CENTER, ILanguageManager::GetLanguageManager()->GetString(SETTINGS_ID), STATIC_HEADER1_ID));
	aWindows.push_back(Window(STATIC, 10, 30, 415, 15, SS_LEFT, ILanguageManager::GetLanguageManager()->GetString(VIEW_COLUMN_ID), STATIC_VIEW_ID));
	aWindows.push_back(Window(CHECK_BOX, 10, 45, 200, 20, NULL, ILanguageManager::GetLanguageManager()->GetString(QUANTITY_FAMILY_ID), CHECK_BEES_ID));
	aWindows.push_back(Window(CHECK_BOX, 215, 45, 200, 20, NULL, ILanguageManager::GetLanguageManager()->GetString(AMOUNT_BROOD_ID), CHECK_BROOD_ID));
	aWindows.push_back(Window(CHECK_BOX, 10, 65, 200, 20, NULL, ILanguageManager::GetLanguageManager()->GetString(AMOUNT_HONEY_ID), CHECK_HONEY_ID));
	aWindows.push_back(Window(CHECK_BOX, 215, 65, 200, 20, NULL, ILanguageManager::GetLanguageManager()->GetString(AMOUNT_WOX_ID), CHECK_WOX_ID));
	aWindows.push_back(Window(CHECK_BOX, 10, 85, 200, 20, NULL, ILanguageManager::GetLanguageManager()->GetString(AMOUNT_FRAME_ID), CHECK_FRAME_ID));
	aWindows.push_back(Window(CHECK_BOX, 215, 85, 200, 20, NULL, ILanguageManager::GetLanguageManager()->GetString(AMOUNT_HOUSING_ID), CHECK_HOUSING_ID));
	aWindows.push_back(Window(CHECK_BOX, 10, 105, 200, 20, NULL, ILanguageManager::GetLanguageManager()->GetString(BIRTHDAY_BEE_QUEEN_ID), CHECK_BIRTHDAY_BEE_QUEEN_ID));
	aWindows.push_back(Window(CHECK_BOX, 215, 105, 200, 20, NULL, ILanguageManager::GetLanguageManager()->GetString(EXIST_BEE_QUEEN_ID), CHECK_EXIST_BEE_QUEEN_ID));
	aWindows.push_back(Window(CHECK_BOX, 10, 125, 200, 20, NULL, ILanguageManager::GetLanguageManager()->GetString(TYPE_FAMILY_ID), CHECK_TYPE_ID));
	aWindows.push_back(Window(CHECK_BOX, 215, 125, 200, 20, NULL, ILanguageManager::GetLanguageManager()->GetString(COLUMN_NOTE_ID), CHECK_NOTE_ID));
	return aWindows;
}

TypeField::table CFamilyViewSettings::GetTypeTable(){
	return TypeField::FAMILIES;
}

CRect CFamilyViewSettings::GetSizeRegion(){
	return CRect(CPoint(10, 150), CSize(250, 245));
}

void CFamilyViewSettings::PostSave(){
	IEventManager::GetEventManager()->SendEvent(FAMILY_STN_CHANGE_EVENT);
}

void CFamilyViewSettings::SetState(const std::tstring& strId, const std::tstring& strState){
	__super::SetState(strId, strState);
	if(strId == CHECK_BEES_ID && strState == CHECK_BOX_STATE_1 || 
		strId == CHECK_BROOD_ID && strState == CHECK_BOX_STATE_1 || 
		strId == CHECK_WOX_ID && strState == CHECK_BOX_STATE_1)
		m_aChange[CHECK_FRAME_ID] = CHECK_BOX_STATE_1;
	if(strId == CHECK_FRAME_ID && strState == CHECK_BOX_STATE_2){
		m_aChange[CHECK_BEES_ID] = CHECK_BOX_STATE_2;
		m_aChange[CHECK_BROOD_ID] = CHECK_BOX_STATE_2;
		m_aChange[CHECK_WOX_ID] = CHECK_BOX_STATE_2;
	}
}